# -*-coding: utf-8 -*-
import datetime
from config import db

class Gallery(db.Model):
    '''
    Gally model
    '''
    __table_args__ = {
        'mysql_charset': 'utf8',
        'mysql_engine': 'innodb',
    }
    id = db.Column(db.Integer, primary_key=True)
    source = db.Column(db.String(255), default='')
    href = db.Column(db.String(255), default='')
    title = db.Column(db.String(255), default='')
    desc = db.Column(db.TEXT)
    cover = db.Column(db.String(255), default='')
    original_src = db.Column(db.String(255), default='')
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    @classmethod
    def add(cls, source, href, title, original_src='', cover='', desc=''):

        gallery = cls(source=source,
                     href=href,
                     title=title,
                     desc=desc,
                     original_src=original_src,
                     cover=cover)
        db.session.add(gallery)
        db.session.commit()
        return gallery


class Picture(db.Model):
    '''
    picture table
    '''
    __table_args__ = {
        'mysql_character': 'utf8',
        'mysql_charset': 'innodb',
    }
    id = db.Column(db.Integer, primary_key=True)
    gallery_id = db.Column(db.Integer, default=0)
    url = db.Column(db.String(255), default='')
    desc = db.Column(db.TEXT)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

